<?php
/**
 * 淘宝IP库
 * IP转换为位置信息
 */
function ip2addr($ip=null) {
    return 'test';
    
    if(!$ip) {
        return 'unknown';
    }
    
    $addr_json = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip);
    $addr_obj = json_decode($addr_json);
    
    if(($addr_obj->code)==1) {
        $addr_data_obj = $addr_obj->data;
        $c = $addr_data_obj->country;
        $r = $addr_data_obj->region;
        $i = $addr_data_obj->isp;
        
        return $c.' '.$r.' ['.$i.']';
    }
    
    return 'unknown';
}